import Title from '../Title';
import { Space } from 'antd';
import dayjs from 'dayjs';
import { useAuthStore } from '@/store/useAuthStore';
import useSWR from 'swr';
import { locationSpaceUsageApi } from '@/api/dashboard';
import Chart from './Chart';
import { useNewBarData } from '../../hooks/useBarDataNew';
import { useGlobeData } from '../../hooks/useGlobeData'; 

export function BarChart(props: { title: string, unit: string }) {
  const { onwayInventoryBarData, warehouseInventoryBarData, warehouseShipmentBarData } = useNewBarData();
  const dataMap: any = {
    在途库存分布: onwayInventoryBarData,
    仓库库存分布: warehouseInventoryBarData,
    仓库出库分布: warehouseShipmentBarData,
  };


  const dataset = dataMap[props.title]

  return (
    <Space
      style={{
        padding: '12px 2px 10px 24px',
        background: 'rgba(0,0,0,0.1)',
        borderRadius: 16,
        flex: 1,
        marginRight: '6px',
      }}
      direction="vertical"
      size={12}
    >
      <Title title={props.title} unit={props.unit} />
      <div
        style={{
          width: '400px',
          height: '182px',
          marginLeft: '-20px',
          marginTop: '-35px',
        }}
      >
        <Chart dataset={dataset} />
      </div>
    </Space>
  );
}
